package com.hyteria.render;

import org.lwjgl.util.vector.Vector;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.geom.Vector2f;

public class Renderable {
	private Shape 		shape;
	private Image		image;

	private Color color = new Color(Color.white);
	private float x,y;
	private float sX, sY; //These will be set by the set width/height functions to ensure that the shapes/images of fixed size will scale to the parameter size
	
	public float getX() { return x;}
	public void setX(float x){ 
		this.x=x;
		if(shape != null){
			shape.setX(x);
		}
	}
	public float getY() { return y;}
	public void setY(float y){ 
		this.y=y;
		if(shape != null){
			shape.setY(y);
		}
	}
	
	public float getWidth(){ 
		if(shape != null){
			return shape.getWidth()*sX;
		}
		
		if(image != null){
			return (float)image.getWidth()*sX;
		}
		
		return 0;
	}
	public void setWidth(float w){
		if(shape != null){
			sX = w / shape.getWidth();
		}else if(image != null){
			sX = w / image.getWidth();
		}
		
		sX = 1;
	}
	
	public float getHeight(){ 
		if(shape != null){
			return shape.getHeight()*sY;
		}
		
		if(image != null){
			return (float)image.getWidth()*sY;
		}
		
		return 0;
	}
	public void setHeight(float h){
		if(shape != null){
			sY = h / shape.getHeight();
		}else if(image != null){
			sY = h / image.getHeight();
		}
		
		sY = 1;
	}
	
	public void setColor(Color c){ color = c; }
	public Color getColor(){ return color; }
	
	public Shape getShape(){ return shape; }
	public void setShape(Shape s){ shape = s; setWidth(s.getWidth()); setHeight(s.getHeight()); setX(s.getX()); setY(s.getY());}
	
	public Image getImage(){ return image; }
	public void setImage(Image i){ image = i; setWidth(i.getWidth()); setHeight(i.getHeight()); }
	
	public int getDepth() throws Exception { return Renderer.getRenderableDepth(this); }
	public void setDepth(int depth){ Renderer.setRenderableDepth(this, depth); }
	
	public void draw(Graphics g){
		g.pushTransform();
		g.scale(sX, sY);
		if(getShape() != null){
			g.setColor(getColor());
			g.fill(getShape());
		}
		
		if(getImage() != null){
			g.drawImage(image,x,y);
		}
		
		g.popTransform();
	}
}
